package com.hongdee.scm.initStock.controller;

import com.hongdee.common.util.TokenUtil;
import com.hongdee.scm.initStock.service.ITScmInitStockService;
import com.hongdee.scm.inputinvoice.entity.TScmInvoiceDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/9/22.
 */
@RestController
@RequestMapping("/scm/initStock")
public class TScmInitStockController {

    @Autowired
    private ITScmInitStockService itScmInitStockService;

    /**
     * 初始化库存导入
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping("/importIn")
    @ResponseBody
    public Map importIn(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "start", defaultValue = "0") String start,
                        @RequestParam(name = "limit", defaultValue = "100000") String limit
     ) throws Exception {

        Map map = this.itScmInitStockService.importIn(uid,start,limit);

        map.put("success", true);
        map.put("msg", "操作成功！");
        return map;
    }

    /**
     * 匹配vin后8位
     * @param uid
     * @param token
     * @param start
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping("/importInSecond")
    @ResponseBody
    public Map importInSecond(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token,
                        @RequestParam(name = "start", defaultValue = "0") String start,
                        @RequestParam(name = "limit", defaultValue = "100000") String limit
    ) throws Exception {

        Map map = this.itScmInitStockService.importSecond(uid,start,limit);

        map.put("success", true);
        map.put("msg", "操作成功！");
        return map;
    }

    /**
     * 查询库存明细中未导入的车辆vin
     * @param uid
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping("/ifmatch")
    @ResponseBody
    public Map ifmatch(@RequestParam(name = "uid", defaultValue = "") String uid,
                        @RequestParam(name = "token", defaultValue = "") String token
    ) throws Exception {

        String cid = TokenUtil.getCompanyId(uid);
        Map map = this.itScmInitStockService.ifmatch(cid,"0","10000");

        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }

    /**
     * 刷新配置车型车系
     * @param uid
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping("/refreshCar")
    @ResponseBody
    public Map refreshCar(@RequestParam(name = "uid", defaultValue = "") String uid,
                       @RequestParam(name = "token", defaultValue = "") String token
    ) throws Exception {

        this.itScmInitStockService.refreshCar(uid);
        Map  map = new HashMap();
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }

    /**
     * 获取72数据
     * @param uid
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping("/getFrom72")
    @ResponseBody
    public Map getFrom72(@RequestParam(name = "uid", defaultValue = "") String uid,
                         @RequestParam(name = "token", defaultValue = "") String token,
                         @RequestParam(name = "table", defaultValue = "") String table
    ) throws Exception {

        this.itScmInitStockService.getFrom72(uid,table);
        Map  map = new HashMap();
        map.put("success", true);
        map.put("msg", "查询成功！");
        return map;
    }

    /**
     * 把72上获取的数据插入74
     * @param uid
     * @param token
     * @return
     * @throws Exception
     */
    @RequestMapping("/insertTo74")
    @ResponseBody
    public Map insertTo74(@RequestParam(name = "uid", defaultValue = "") String uid,
                          @RequestParam(name = "token", defaultValue = "") String token,
                          @RequestParam(name = "table", defaultValue = "") String table,
                          @RequestParam(name = "data",defaultValue = "") String data,
                          @RequestBody Map dataList
    ) throws Exception {

        this.itScmInitStockService.insertTo74(data,uid,table);
        Map  map = new HashMap();
        map.put("success", true);
        map.put("msg", "导入成功！");
        return map;
    }

}
